###############################################
# GRAPHS FOR GROUND PROFILES WITH FIXED VALUES:
###############################################
stap=0.01;seq=seq(.005,.995,.01)
D1=dnorm(seq,0.40,0.04);D1=D1/(sum(D1)*stap)
D2=dnorm(seq,0.70,0.10);D2=D2/(sum(D2)*stap)
G1=(D1+D2)/2
G2=dnorm(seq,0.45,0.15);G2=G2/(sum(G2)*stap)
plot(seq,G1,col='blue',type='l',lwd=2,ylim=c(0,8),axes=FALSE,
main=c(paste('Respondent Profiles for'),
paste('Group 1 (mean=.55) and Group 2 (mean=.45)')),
xlab='Probability of Behaviour',ylab='Likelihood of Probability')
axis(side=1,at=seq(0,1,0.10));axis(side=2,at=seq(0,8,2),las=1)
lines(seq,G2,col='red',lwd=2)
legend('topright',bty='n',
c('Profile Group 1','Profile Group 2'),
fill=c('blue','red'))



###############################################
# SAMPLE FOR SPECIFIED NUMBER OF MEN AND WOMEN:
###############################################
OBCD_TOTAAL=matrix(,10000,38)
T=0
v=c(2*seq(5,100,5),2*seq(110,200,10),2*seq(250,500,50),1500,2000)
for(w in 1:38)
{

N=0
OBCD=numeric()
while(N<10000)
{

A=sample(c(0,1),v[w],replace=TRUE,prob=c(.5,.5));table(A)
n_S1=A[A==0];length(n_S1)
n_S2=A[A==1];length(n_S2)



#############################################################################
# SAMPLE RESPONDENT DATA OBSERVATIONS FROM GROUND PROFILES WITH FIXED VALUES:
#############################################################################
if((length(n_S1>0))&(length(n_S2>0)))
{

S1=sample(seq,length(n_S1),replace=TRUE,prob=G1);length(S1)
S2=sample(seq,length(n_S2),replace=TRUE,prob=G2);length(S2)



##################################################################
# ORIGINAL CLIFF'S DELTA FOR SAMPLED RESPONDENT DATA OBSERVATIONS:
##################################################################
y1=S1;y2=S2
DIF=matrix(0,length(y1),length(y2))
for(x in 1:length(y1))
{
for(y in 1:length(y2))
{
dif=(y1[x]-(y2[y]))
DIF[x,y]=dif
}}
DIF=sign(DIF)
CD=(sum(table(DIF[DIF==1]))-sum(table(DIF[DIF==-1])))/(length(y1)*length(y2))

OBCD=c(OBCD,CD)
N=N+1
}}

T=T+1;print(T)
OBCD_TOTAAL[,w]=OBCD
}


